/*
 *
 *	@titre: popup.
 *	@description: javascript popup - télé Z
 *	@auteur: neov - http://www.neov.net.
 *	@creation: 270109.
 *	@modification: -.
 *
*/

var fadeTime = 300;
var lastOpen = null;

function afficherMasque()
{
	var w = $('body').width();
	var mh = $('body').height();
	var ih = $(document).height();

	if ( mh < ih ) mh = ih;		

	$('#masque')
		.css({width: w + 'px', height: mh +'px', opacity: 0.5, filter:'Alpha(Opacity=50)'})
		.fadeIn(fadeTime);

}

// affichage popup

$.fn.showPop = function(el, f)

{
	
	$(this).each(
		function()
		{
			$(this).click(
				function()
				{
					if (f) f.call();
					
					var extraPos = 0;
					if( $(window).height() < $(el).height() ) extraPos = 150;
					var tPos = ( $(window).height() - $(el).height() )/2 + $(window).scrollTop() + extraPos;
					var lPos = ( $(window).width() - $(el).width() )/2;
					if (lastOpen != null) $(lastOpen).fadeOut(fadeTime);
					$(el)
						.fadeIn(fadeTime)
						.css({ top: tPos + 'px', left: lPos + 'px' });
					afficherMasque();
					
					lastOpen = el;
					$('.points').css( 'visibility','hidden');
					
					return false;
				}
			);
		}
	);
	
}

$.fn.showElem = function(url)
{ 
	var tPos = ( $(window).height() - $(this).height() )/2 + $(window).scrollTop();
	var lPos = ( $(window).width() - $(this).width() )/2;
	
	$(this)
		.fadeIn(fadeTime)
		.css({ top: tPos + 'px', left: lPos + 'px' });
	
	afficherMasque();

	return false;
}



$.fn.hidePop = function()
{
	$(this).each(
		function()
		{
			$(this).click(
				function()
				{
					$('#masque').fadeOut(fadeTime);
					$(lastOpen).fadeOut(fadeTime);
					$('.points').css( 'visibility','visible');
					
					return false;
				}
			);
		}
	);
}


$(function() {
//	$('.pop-up').hide();
	
	// ouverture popup
	$('.img-pop').showPop('#light');
	$('.visuadvert').showPop('#popvisuadvert');
	$('.modifadvert').showPop('#popvisuadvertmodif');
	$('.searchadvert').showPop('#popsearchadvert');
	

	// fermeture popup
	$('.close').hidePop();
	
});